import type { CloudFilterBarScheme } from '@/components/filter-bar/types'
import { buildColumns } from '@/utils'

export default function useTableColumn() {
  const filterSchemes: CloudFilterBarScheme = {
    widgets: [
      {
        widget: 'select',
        field: 'apply_result',
        options: [
          { label: '成功', value: 1 },
          { label: '失败', value: 2 },
          { label: '申请中', value: 3 }
        ],
        allText: '全部状态'
      },
      {
        widget: 'strong-search',
        placeholder: '默认按照站点搜索',
        options: [
          {
            label: '站点',
            field: 'site_domain_keyword'
          },
          {
            popover: 'date',
            popoverOption: {
              dateProps: {
                startKey: 'created_at_start',
                endKey: 'created_at_end'
              }
            },
            label: '申请时间',
            field: 'created_at'
          }
        ]
      }
    ]
  }
  const columns = buildColumns([
    {
      title: '站点',
      dataIndex: 'site_domain',
      format: 'copy'
    },
    {
      title: '证书模式',
      dataIndex: 'source',
      slotName: 'source'
    },
    {
      title: 'ACME账号',
      dataIndex: 'acme_account_email'
    },
    {
      title: '状态',
      dataIndex: 'apply_result',
      slotName: 'status'
    },
    {
      title: '日志',
      dataIndex: 'log',
      slotName: 'log'
    },
    {
      title: '申请时间',
      dataIndex: 'created_at',
      sortable: sortableSettings,
      format: 'date-time'
    },
    {
      title: '操作',
      width: 100,
      slotName: 'action'
    }
  ])
  return {
    columns,
    filterSchemes
  }
}
